<%@tag pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<div align="right">
<script type="text/javascript">
	var LODOP; 
	var printName="";//打印机名称
	var status="";

	function valSize(item,url){

		var exp=$("#expressNo").html();
		if(exp.length>0){
			$(item).attr("href","#"+url);
		}else{
			alert(message);
			$(item).attr("href","ss");
			return false;
		}   
		packFormPrinter("packFormStylePrint");
		status="packForm";
		
		return true;
	}
	function getAjaxPackformStyle() {
		var packformStylesId = $("#packformStylesId").val();
		if (packformStylesId == "" || packformStylesId == null) {
			alert("还没有这个随箱单");
			return;
		}
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/packformStyle/getAjaxPackformStyle',
			data : 'packformStylesId=' + $("#packformStylesId").val(),
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {

					packformName = data.name;
				
				} else if (data.status == "0") {
					alert("获取随箱单信息错误！");
				}

			},
			error : function() {
				alert("服务器异常");
			}
		});
	}
	function doPageAjaxPrinter(){
		printName= $("#packFormStylePrint").val();
		var ordenos = $("#txt_orderno").val().trim();
   		var packformStyleId = $("#packformStylesId").val();//随箱单样式
        //showBg();
		$.ajax({
				type : 'post',
				url : '${ctx}/print/ajaxPrintPackFormOrdenos',
				data : 'ordenos=' + ordenos+'&packformStyleId='+packformStyleId,
				dataType : 'json',
				success : function(data) {
					 if (data.status == "1") {
						initLodop();
						$.each(data.content, function(i) {
							 printStyle(packformName,data.content[i].taskName,printName,data.content[i].content,data.content[i].ordeno,data.content[i].expressNo,data.content[i].taskName,data.content[i].customerCode);
						});
						/***bug554 beigin remove by zhangweize  2016-10-31*************/
						/* ajaxWorkTaskPackFormStatus(ordenos);  */
						/***bug554 end remove by zhangweize  2016-10-31*************/
					      closeBg();
					} else if (data.status == "-3") {
				    	closeBg();
						alert("请输入正确的运单号！");
					} else if (data.status == "0") {
					    closeBg();
						alert("加载错误！");
					}

				},

				error : function() {
	                alert("服务器异常");
				}
			});
	}
	function initLodop() {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document
				.getElementById('LODOP_EM'));
	}
	function printStyle(indentfy,taskName, printerName, printContent,ordeno, expressNo,rankno,customerCode){   
        printFivePackStyle(taskName,printerName,printContent,ordeno,expressNo,rankno,customerCode);
    }
	function printFivePackStyle(taskName, printerName, printContent,ordeno, expressNo,rankno,customerCode) {
		LODOP.PRINT_INIT(taskName);
		LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5") ;
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(60, 0, "100%", "100%", strCenterStyle+ printContent);
		LODOP.ADD_PRINT_BARCODE(50, 560, 200, 50, "128B", ordeno);
		if (LODOP.SET_PRINTER_INDEXA(printerName)) {
			LODOP.PRINT();
		}
	}
	function ajaxWorkTaskPackFormStatus(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxWorkTaskPackFormStatus',
			data : 'workIds=' + item,
			dataType : 'json',
			success : function(data) {
			},
			error : function() {
				alert("服务器异常");
			}
		});
	}
	function ajaxExpressStyle() {
		var tmporderno = $("#txt_orderno").val().trim();
		var tmpexpressNo = $("#txt_expressNo").val().trim();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/ajaxExpressStyle',
			//data : 'companyCode=' + '${workTask.companyCode}'+'&areaGroupCode='+'${workTask.warehouseCode}'+'&customerCode='+'${workTask.customerCode}'+'&type='+type,
			data : 'companyCode=&areaGroupCode='+'${workTask.warehouseCode}'+'&customerCode='+'${workTask.customerCode}'+'&type='+type,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					var temp="<option value=''></option>";
					$.each(data.content,function(i,obj){
					       temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
					       
					});
					$("[name='expressStylesId']").html(temp);
					$("[name='expressStylesId']").trigger("chosen:updated");
					getAjaxExpress();
				}
			},

			error : function() {

			}
		});
		
	}

</script>
</div>
<script type="text/javascript">
$("#printer").click(function(){
$("#printer").attr("disabled", "disabled");
  pageAjaxPrinter();
});
	if("express"=='${status}'){
	  
	}
</script>
<div class="row" align="right" style="padding-right: 20px;" >
	<div>
		<a href="#printAllPackFormStyle" role="button" data-toggle="modal"
			class="btn btn-primary" onclick="valSize(this,'printAllPackFormStyle');"
			style="margin-left: 20px;">打印随箱单</a>
	</div>
</div>

 <div class="modal fade"
	tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
	aria-hidden="true" id="printAllPackFormStyle">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h3 id="myModalLabel">
                                                        打印随箱单信息
				</h3>
				<span id="messageLable"></span>
			</div>
			<div class="modal-body">
				<div class="form-group row">
				    <div class="col-sm-9">
						<div class="input-group col-sm-12">
							<span class="input-group-text">   选择打印机: </span> 
							<select id="packFormStylePrint" name="packFormPrinter" class="form-control">
							</select>
						</div>
					</div>
				</div>
				
				<div class="form-group row">
				    <div class="col-sm-9">
						<div class="input-group col-sm-12">
							<span class="input-group-text">   选择随箱单:</span> 
							<select id="packformStylesId" name="packformStyleId" onchange="getAjaxPackformStyle();" class="form-control">
			
							</select>
						</div>
					</div>
				</div>
				
				
			</div>

			<div class="modal-footer">
				<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true"
					onclick="doPageAjaxPrinter()"> 立即打印 </a>
				<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
			</div>
			
		</div>
	</div>
</div>
